/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.techshop.controller;

import com.techshop.model.Phone;
import com.techshop.model.PhoneTechnicalSpecifications;
import com.techshop.model.PhoneTechnicalSpecificationsId;
import com.techshop.model.TechnicalSpecifications;
import com.techshop.service.PhoneService;
import com.techshop.service.PhoneTechSpecService;
import com.techshop.service.TechnicalSpecificationsService;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author Hai-PC
 */
@ManagedBean(name="phoneTechSpecController")
@SessionScoped
public class PhoneTechSpecController extends AbstractController
{    
   

   

    public PhoneTechSpecController() {
    
    }
        

    PhoneTechnicalSpecifications selectPhoneTechSpec = new PhoneTechnicalSpecifications();   
        private List<Phone> phoneList;
        private List<TechnicalSpecifications> listTechnicalSpecifications;

    public List<TechnicalSpecifications> getListTechnicalSpecifications() {
     listTechnicalSpecifications =getTechnicalSpecificationsService().findAllByPhoneID(selectPhoneTechSpec.getId().getPhoneId());
     
     return listTechnicalSpecifications;
        
    }

    public void setListTechnicalSpecifications(List<TechnicalSpecifications> listTechnicalSpecifications) {
        this.listTechnicalSpecifications = listTechnicalSpecifications;
    }

    public List<Phone> getPhoneList() {
        setPhoneList(getPhoneService().getAll());
        return phoneList;
    }

    public void setPhoneList(List<Phone> phoneList) {
        this.phoneList = phoneList;
    }
    @ManagedProperty(value = "#{phoneTechnicalSpecificationsService}")
    PhoneTechSpecService phoneTechSpecService;
    @ManagedProperty(value = "#{phoneService}")
    private PhoneService phoneService;
    
     @ManagedProperty(value = "#{technicalSpecificationsService}")
    private TechnicalSpecificationsService technicalSpecificationsService;

    public TechnicalSpecificationsService getTechnicalSpecificationsService() {
        return technicalSpecificationsService;
    }

    public void setTechnicalSpecificationsService(TechnicalSpecificationsService technicalSpecificationsService) {
        this.technicalSpecificationsService = technicalSpecificationsService;
    }
    
    public PhoneService getPhoneService() {
        return phoneService;
    }

    public void setPhoneService(PhoneService phoneService) {
        this.phoneService = phoneService;
    }
     @PostConstruct
     public void init()
     {
         selectPhoneTechSpec = new PhoneTechnicalSpecifications();
         selectPhoneTechSpec.setId(new PhoneTechnicalSpecificationsId());
         selectPhoneTechSpec.setPhone(new Phone());
//         for(TechnicalSpecifications ts:getListTechnicalSpecifications())
//         {
//             map.put(ts.getId(),ts.getDisplayname());
//         }
//                     
     }
     
    public PhoneTechnicalSpecifications getSelectPhoneTechSpec() {
        return selectPhoneTechSpec;
    }

    public void setSelectPhoneTechSpec(PhoneTechnicalSpecifications selectPhoneTechSpec) {
        this.selectPhoneTechSpec = selectPhoneTechSpec;
    }

    public PhoneTechSpecService getPhoneTechSpecService() {
        return phoneTechSpecService;
    }

    public void setPhoneTechSpecService(PhoneTechSpecService phoneTechSpecService) {
        this.phoneTechSpecService = phoneTechSpecService;
    }
      
    public void btnCreate(){
//        TechnicalSpecifications ts=getTechnicalSpecificationsService().getByID(selectPhoneTechSpec.getTechnicalSpecifications().getId());
//        listTechnicalSpecifications.remove(ts);
        if(getPhoneTechSpecService().insert(selectPhoneTechSpec)){
            addInfoMessage("Thêm thành công");
        }else{
            addErrorMessage("Thêm không thành công");
        }
        selectPhoneTechSpec.setInfo("");
    }
    
    
//    public void btnUpdate(){
//        if(getCategoryService().update(getSelectcategory())){
//            addInfoMessage("Cập nhật nhà sản xuất thành công");
//        }else{
//            addErrorMessage("Cập nhật nhà sản xuất không thành công");
//        }
//    }
//    
//    
//    public void btnDelete(){
//        if(getCategoryService().delete(getSelectcategory())){
//            addInfoMessage("Xóa loaij thành công");
//        }else{
//            addErrorMessage("Xóa nhà sản xuất không thành công");
//        }
//    }
    
    public void resetSelectPhoneTechSpec(){
        selectPhoneTechSpec = new PhoneTechnicalSpecifications();
    }
    
    
    /**
     * @return the listcategory
     */
    
}